package com.sxt.pro.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;

/**
 * @Description  websocket配置监测端点，和客户端相关订阅配置STOMP
 * @Author xinxiaokang
 * @Date
 */
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer{

	public void registerStompEndpoints(StompEndpointRegistry registry) {
          //客户端和服务端交互端点
		registry.addEndpoint("/endpoint-websocket").setAllowedOrigins("*").withSockJS();
	}


	@Override
	public void configureMessageBroker(MessageBrokerRegistry registry) {
		//服务端广播消息的路径前缀，客户端需要相应订阅/topic/yyy这个地址的消息
		registry.enableSimpleBroker("/topic", "/chat");
		//客户端需要把消息发送到/app/xxx地址
		registry.setApplicationDestinationPrefixes("/app");
		
	}

	
}


